// 接口定义和函数注释均使用单行样式
import { makeAutoObservable } from 'mobx';

// 标签数据接口定义
export interface LableData {
    id: string | number; // 标签ID
    text: string; // 标签文本
    type: 'default' | 'primary' | 'success' | 'warning' | 'error'; // 标签类型
    size?: 'small' | 'medium' | 'large'; // 标签大小
    closable?: boolean; // 是否可关闭
    [key: string]: any; // 额外数据
}

// Lable组件状态管理类
class LableStore {
    constructor() {
        // 初始化mobx观察
        makeAutoObservable(this, {}, { deep: false });
    }

    // 标签列表数据
    lableList: LableData[] = [];

    // 设置标签列表
    setLableList(lables: LableData[]) {
        this.lableList = lables;
    }

    // 添加单个标签
    addLable(lable: LableData) {
        this.lableList.push(lable);
    }

    // 批量添加标签
    addLables(lables: LableData[]) {
        this.lableList = [...this.lableList, ...lables];
    }

    // 根据ID删除标签
    removeLable(id: string | number) {
        this.lableList = this.lableList.filter(lable => lable.id !== id);
    }

    // 批量删除标签
    removeLables(ids: (string | number)[]) {
        this.lableList = this.lableList.filter(lable => !ids.includes(lable.id));
    }

    // 根据ID更新标签
    updateLable(id: string | number, updates: Partial<LableData>) {
        const index = this.lableList.findIndex(lable => lable.id === id);
        if (index !== -1) {
            this.lableList[index] = { ...this.lableList[index], ...updates };
        }
    }

    // 清空所有标签
    clearLables() {
        this.lableList = [];
    }

    // 根据ID获取标签
    getLableById(id: string | number): LableData | undefined {
        return this.lableList.find(lable => lable.id === id);
    }

    // 根据类型获取标签列表
    getLablesByType(type: LableData['type']): LableData[] {
        return this.lableList.filter(lable => lable.type === type);
    }

    // 生成默认示例标签数据
    generateDefaultLables() {
        const defaultLables: LableData[] = [
            { id: 1, text: '默认标签', type: 'default', closable: true },
            { id: 2, text: '主要标签', type: 'primary', closable: true },
            { id: 3, text: '成功标签', type: 'success', closable: true },
            { id: 4, text: '警告标签', type: 'warning', closable: true },
            { id: 5, text: '错误标签', type: 'error', closable: true },
            { id: 6, text: '小标签', type: 'default', size: 'small', closable: false },
            { id: 7, text: '大标签', type: 'primary', size: 'large', closable: true },
        ];
        this.setLableList(defaultLables);
    }

    // 获取标签总数
    getLableCount(): number {
        return this.lableList.length;
    }
}

// 创建并导出store实例
const lableStore = new LableStore();

export default lableStore;